package jp.sinya.register.dao;

import java.io.InputStream;
import java.util.Properties;

/**
 * 通过工厂类 然后去配置properties文件，预设了完整的文件包名路径，来通过反射创建 Dao 类
 */
public class DaoFactory {
    private static Properties properties = null;

    static {
        try {
            InputStream in = DaoFactory.class.getClassLoader().getResourceAsStream("dao.properties");
            properties = new Properties();
            properties.load(in);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static UserDao2 getUserDao() {
        String daoClassName = properties.getProperty("jp.sinya.register.dao.UserDao");
        try {
            Class clazz = Class.forName(daoClassName);
            return (UserDao2) clazz.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
